#include "Protocol.hpp"
#include "Sock.hpp"
int main(int argc, char **argv)

{
    if (argc != 3)
    {
        cout << "Usage: " << argv[0] << " ip port" << endl;
        exit(1);
    }
    int sock = Sock::Socket();
    Sock::Connect(sock, argv[1], atoi(argv[2]));

    //业务逻辑
    request_t req;

    cout << "Please enter your Data one # ";
    cin >> req.x;
    cout << "Please enter your Data tow# ";
    cin >> req.y;
    cout << "Please enter your Data operator # ";
    cin >> req.op;
    // write(sock,&req,sizeof(req));

    std::string join_string = SerializeRequest(req);
    write(sock, join_string.c_str(), join_string.size());

    // response_t resp;
    // ssize_t sz = read(sock,&resp,sizeof(resp));
    // if(sz==sizeof(resp))
    // {
    //     cout<<"code[0:success]: "<<resp.code<<endl;
    //     cout<<"result: "<< resp.result<<endl;
    // }
    char buffer[1024];
    response_t resp;
    ssize_t sz = read(sock, buffer, sizeof(buffer) - 1);
    if (sz > 0)
    {
        buffer[sz] = '\0';
        std::string str = buffer;
        DeserilizeResponse(str, resp);
    }
    cout << "code[0:success]: " << resp.code << endl;
    cout << "result: " << resp.result << endl;
    return 0;
}
